package com.ag.dgm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.ag.bean.TbPlanRegion;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.dgm.service.PlanRegionService;

@Controller("PlanRegionAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class PlanRegionAction extends BaseAction {
	private static final long serialVersionUID = -4951566435559209769L;


	@Resource(name = "planRegionService")
	private PlanRegionService planRegionService;

	private List<TbPlanRegion> tbPlanRegionList;
	private String Id;
	private String Name;
	private String Detail;
	private String result;
	TbPlanRegion tbPlanRegion = new TbPlanRegion();

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public void setTbPlanRegionList(List<TbPlanRegion> tbPlanRegionList) {
		this.tbPlanRegionList = tbPlanRegionList;
	}

	public String getId() {

		return Id;
	}

	public void setId(String Id) {
		this.Id = Id;
	}

	public String getName() {
		return Name;
	}

	public void setName(String Name) {
		this.Name = Name;
	}

	public String getDetail() {
		return Detail;
	}

	public void setDetail(String Detail) {
		this.Detail = Detail;
	}

	public List<TbPlanRegion> getTbPlanRegionList() {
		return tbPlanRegionList;
	}

	public String find() {
		try {
			tbPlanRegionList = planRegionService.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbPlanRegion.setPrId(Id);
		this.setResult("删除成功");
		try {
			planRegionService.delete(tbPlanRegion);
		} catch (Exception e) {
			this.setResult("删除不成功");
		}
		return "delete_succ";
	}

	public String modify() {
		tbPlanRegion.setPrId(Id);
		tbPlanRegion.setPrName(Name);
		tbPlanRegion.setPrDetail(Detail);
		tbPlanRegion.setA(IDUtil.PRESERVE);
		this.setResult("修改成功");
		try {
			planRegionService.modify(tbPlanRegion);
		} catch (Exception e) {
			this.setResult("修改不成功");
		}
		return "modify_succ";
	}

	public String add() {

		try {

		tbPlanRegion.setPrName(Name);
		tbPlanRegion.setPrDetail(Detail);
		tbPlanRegion.setA(IDUtil.PRESERVE);  
		this.setResult("增加成功");
			planRegionService.save(tbPlanRegion);

		} catch (Exception e) {
			this.setResult("增加不成功");
		}
//		System.out.print(result.toString()+"**************************");
		return "add_succ";
	}
}
